import React, {Component} from "react";
import {
    View,
    StyleSheet,
    WebView,
    ActivityIndicator,
} from 'react-native';
import HttpUtils from "../common/HttpUtils"

const host = 'http://sxakjc.com/api/auth/login/'

export default class Sas extends Component {
    static navigationOptions = ({navigation}) => {
        const params = navigation.state.params || {};

        return {
            headerTitle: params.title,
        };
    }

    constructor(props) {
        super(props);
        this.state = {
            url: '',
            isLoading: true,
        }
    }

    componentWillMount() {
        fetch(host + this.props.navigation.state.params.token)
            .then(result => {
                console.log(result);
                if (result.status == 200) {
                    this.setState({
                        url: 'http://sxakjc.com/sas/dashboard/vmap?layouts=mini'
                    })
                } else {
                    this.props.navigation.goBack()
                }


            })
    }

    onLoad() {
        if (!this.state.url) {
            return;
        }

        this.setState({
            isLoading: false
        })
    }

    render() {
        return (
            <View style={styles.container}>
                <WebView
                    source={{uri: this.state.url}}
                    onLoadEnd={() => {
                        this.onLoad()
                    }}
                />
                <View style={styles.loadingBox}>
                    <ActivityIndicator
                        animating={this.state.isLoading}
                        style={[styles.loadingBox]}
                        size="large"
                        color="#387ef5"
                    />
                </View>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: "white",
    },
    text: {
        fontSize: 20,
    },
    loadingBox: {
        // display: "none",
        position: 'absolute',
        left: 0,
        right: 0,
        top: 100,
    }
})